import 'package:flutter/material.dart';

class CheckBoxPage extends StatefulWidget {
  const CheckBoxPage({Key? key}) : super(key: key);

  @override
  _CheckBoxPageState createState() => _CheckBoxPageState();
}

class _CheckBoxPageState extends State<CheckBoxPage> {
  var flag=true;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('复选框'),
      ),
      body: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          Row(
            children: [
              Checkbox(
                value: this.flag,
                onChanged: (bool? value) {
                  setState(() {
                    this.flag=value!;
                  });
                },
              ),
            ],
          ),
          Row(
            children: [
              Text(this.flag?'选中':'未选中'),
            ],
          ),
          SizedBox(height: 40),
          CheckboxListTile(
            value: this.flag,
            onChanged:(v){
              setState(() {
                this.flag=v!;
              });
            },
            title: Text('问卷调查二:是否了解XXXXX？'),
            subtitle: Text('你是否有了解过历史上这XXX方面的知识。'),
            selected: this.flag,
          ),
          Divider(),
          CheckboxListTile(
            value: this.flag,
            onChanged:(v){
              setState(() {
                this.flag=v!;
              });
            },
            title: Text('问卷调查二:是否了解XXXXX？'),
            subtitle: Text('你是否有了解过历史上这XXX方面的知识。'),
            secondary: Icon(Icons.home),
          ),
        ],
      ),
    );
  }
}
